#ifndef FILE_H
#define FILE_H

#include "Common.h"
#include "Host.h"

class File{
public: enum Status { READY, NOTREADY, NOCOPY, INTRANSIT, DELETED };
private:
    typedef struct _Version{
        Host * _host;
        int _currentTimestamp;
        int _networkTimestamp;
        bool _hasLocalCopy;
        File::Status _status;
        bool _modified;
    }Version;

    string _fileName;
    int _versionNum;
    vector<Version *> _versions;

    int removedLocalCopy(int versionNum);

public:
    File(string fileName, int versionNum);
    ~File();
    // accessors
    string fileName();  // returns name of the file
    int versionNum();   // returns the current largest version number
    Host * host(int versionNum);
    int networkTimestamp(int versionNum);
    bool isModified(int versionNum);
    bool hasLocalCopy(int versionNum);
    int isVersionUpToDate(int versionNum);
    bool isAvailable(int versionNum);
    bool isVersionInTransit(int versionNum);
    File::Status status(int versionNum);

    // some manipulations
    int setHost(int versionNum, Host * host);
    int setModified(bool isModified, int versionNum);
    int setStatus(Status newStatus, int versionNum);
    int setVersionInTransit(int versionNum);
    int addVersion(int versionNum, Host * host, int currentTimestamp);
    int updateTimestamp(int versionNum, Host * host, int networkTimestamp);
    int updateVersion(int versionNum, int currentTimestamp);
    int receivedLocalCopy(int versionNum);
    int deleteFile(int timestamp);

};

#endif
